<template>
	<view class="">
		<view class="content">
			<image class="logo" :src="logo" mode="widthFix"></image>
		</view>
		<view class="input-container">
			<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
			<u--form :model="model1" :rules="rules" ref="uForm" labelPosition="top" class="form-container">
				<u-form-item label="手机号" prop="userInfo.mobile" labelWidth="60px" labelPosition="top" ref="item1">
					<u--input v-model="model1.userInfo.mobile" placeholder="请输入手机号" class="input"></u--input>
				</u-form-item>
				<u-form-item label="密码" prop="userInfo.password" labelWidth="60px" labelPosition="top" ref="item1">
					<u--input v-model="model1.userInfo.password" password placeholder="请输入密码" class="input"></u--input>
				</u-form-item>
			</u--form>
			<view class="btn-container">
				<u-button @click="submit" type="primary" class="btn" :style="btnBgColor">登录</u-button>
			</view>
		</view>
	</view>

</template>

<script>
	import common from '../../js/api/common.js';
	
	const app = getApp();
	const theme_color = app.globalData.get_theme_color();
	
	export default {
		data() {
			return {
				btnBgColor: 'background:' + theme_color,
				logo: app.globalData.data.application_logo,
				showSex: false,
				model1: {
					userInfo: {
						mobile: '',
						password: '',
						device:'wx',
					},
				},
				rules: {
					'userInfo.mobile': {
						type: 'string',
						required: true,
						message: '请输入手机号',
						trigger: ['blur']
					},
					'userInfo.password': {
						type: 'string',
						required: true,
						message: '请输入密码',
						trigger: ['blur']
					},
				},

			};
		},
		onLoad() {

		},
		methods: {
			submit() {
				common.login(this.model1.userInfo).then((res) => {
					if (res.data.code === 200) {
					  // 记录已初始化公共数据状态
					  app.globalData.data.common_data_init_status = 1;
					  // 配置存储
					  var data = res.data.data;
					  uni.setStorageSync(app.globalData.data.cache_config_info_key, data);
					  uni.setStorageSync("shiro", res.header['Set-Cookie']);
					  // 设置底部菜单
					  // self.set_tabbar(data.plugins_themestyle_data);
					  // 用户自动登录处理
					  app.globalData.showToast('登录成功');
					  uni.reLaunch({
					    url: '/pages/home/home'
					  })
					} else {
					  app.globalData.showToast(res.data.msg);
					  // 站点关闭状态则 记录已初始化公共数据状态
					  if (res.data.code == -10000) {
					    app.globalData.data.common_data_init_status = 1;
					  }
					
					  // 首次则再次初始化配置、站点关闭状态则不处理
					  if (status == 0 && app.globalData.data.common_data_init_status == 0) {
					    app.globalData.init_config(1);
					  }
					}
				})
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
	};
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 180rpx;
		width: 180rpx;
		margin-top: 120rpx;
		margin-bottom: 90rpx;
	}

	.input-container {
		padding: 0 60rpx;

		.form-container {
			.input {
				margin: 10rpx 0;
				border-radius: 2rpx;
				height: 60rpx;
				border: none;
				background-color: #F5F5F5;
			}

		}

		.btn-container {
			position: relative;
			top: 60rpx;

			.btn {
				border-radius: 2rpx;
				background-color: #3C72FF;
			}
		}


	}
</style>